package com.sky.controller.admin;

import cn.hutool.http.HttpResponse;
import com.sky.dto.ReportDTO;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.service.WorkSpaceService;
import com.sky.vo.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;

/**
 * 数据统计相关接口
 *
 * @author normal
 * @date 2025年03月05日 下午9:49
 */
@RequestMapping("/admin/report")
@RestController
@Slf4j
@RequiredArgsConstructor
public class ReportController{

    private final OrderService orderService;

    private final WorkSpaceService workspcaeService;
    /**
     * 订单统计接口
     * @param reportDTO
     * @return
     */
    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO> getOrdersStatistics(ReportDTO reportDTO){
        OrderReportVO orderStatisticsVO = orderService.getOrderStatistics(reportDTO);
        return Result.success(orderStatisticsVO);
    }

    /**
     * 营业统计
     */
    @GetMapping("/turnoverStatistics")
    public Result<TurnoverReportVO> getTurnoverStatistics(ReportDTO reportDTO){
        TurnoverReportVO turnoverReportVO = orderService.getTurnoverStatistics(reportDTO);
        return Result.success(turnoverReportVO);
    }

    /**
     * 用户统计
     */
    @GetMapping("/userStatistics")
    public Result<UserReportVO> getUserStatistics(ReportDTO reportDTO){
        UserReportVO orderStatisticsVO = orderService.getUserStatistics(reportDTO);
        return Result.success(orderStatisticsVO);
    }

    /**
     * 销量排行榜TOP10
     */
    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> getTop10(ReportDTO reportDTO){
        SalesTop10ReportVO orderStatisticsVO = orderService.getSalesTop10(reportDTO);
        return Result.success(orderStatisticsVO);
    }

    /**
     * 导入Excel报表接口
     */
    @GetMapping("/export")
    public void export(HttpServletResponse httpResponse) throws IOException {
        workspcaeService.exportExcel(httpResponse);
    }




}
